/*
** parser.c for parser in /home/druart_p/Work/projet/zappy/zappy-2015-2014s-renard_g/serv-src
**
** Made by pierrick druart
** Login   <druart_p@epitech.net>
**
** Started on  Wed Jun 13 12:59:09 2012 pierrick druart
** Last update Tue Jul 10 14:29:05 2012 pierrick druart
*/

#include		<stdio.h>
#include		<stdlib.h>
#include		<string.h>

#include		"server.h"

int			init_x(const char *argv[], unsigned int *i, t_game *game)
{
  if (strncmp("-", argv[*i + 1], 1))
    {
      if (atoi(argv[(*i) + 1]))
	{
	  game->coord.x = atoi(argv[(*i) + 1]);
	  return (0x00000001);
	}
    }
  fprintf(stderr, "Usage: x error.\n");
  return (0);
}

int			init_y(const char *argv[], unsigned int *i, t_game *game)
{
  if (strncmp("-", argv[*i + 1], 1))
    {
      if (atoi(argv[(*i) + 1]))
	{
	  game->coord.y = atoi(argv[(*i) + 1]);
	  return (0x00000010);
	}
    }
  fprintf(stderr, "Usage: y error.\n");
  return (0);
}

int			init_time(const char *argv[], unsigned int *i, t_game *game)
{
  if (strncmp("-", argv[*i + 1], 1))
    {
      if (atoi(argv[(*i) + 1]))
	{
	  game->time = atoi(argv[(*i) + 1]);
	  if (game->time == 0)
	    game->time = 100;
	  return (0);
	}
      else
	{
	  fprintf(stderr, "Usage: time error.\n");
	  return (-1);
	}
    }
  else
    return (-1);
}

int			init_port(const char *argv[], unsigned int *i, t_game *game)
{
  (void)argv;
  if (strncmp("-", argv[*i + 1], 1))
    {
      if (atoi(argv[(*i) + 1]))
	{
	  game->port_index = argv[(*i) + 1];
	  return (0x00000100);
	}
    }
  fprintf(stderr, "Usage: port error.\n");
  return (0);
}

int			init_client(const char *argv[], unsigned int *i, t_game *game)
{
  if (strncmp("-", argv[*i + 1], 1))
    {
      if (atoi(argv[(*i) + 1]))
	{
	  game->nb_player = atoi(argv[(*i) + 1]);
	  return (0x00001000);
	}
    }
  fprintf(stderr, "Usage: nb client error.\n");
  return (0);
}
